# -*- coding: utf-8 -*-
# Version: Python 3.9.7
# Author: TRIX
# Date: 2021-09-12 14:24:01
# Use:批量缩放图片大小 在图片文件夹的同级目录生成缩放后的图片
from os import listdir,path,mkdir
from PIL import Image
def pic_resize(picFolder,scale):
	'''文件夹目录 缩放比例int(0,10) 或 缩放分辨率str weightxheight'''
	outfile=picFolder+'_resized'
	if not path.exists(outfile):
		mkdir(outfile)#如果输出文件夹不存在 创建文件夹

	if isinstance(scale,str):#缩放分辨率str weightxheight
		for file in listdir(picFolder):
			pic=Image.open(picFolder+'\\'+file)
			resW,resH=(scale).lower().split('x')
			resPic=pic.resize((int(resW),int(resH)),Image.ANTIALIAS)
			resPic.save(outfile+'\\'+file,quality=100,dpi=(300,300))
	else:#缩放比例int(0,10)
		for file in listdir(picFolder):
			pic=Image.open(picFolder+'\\'+file)
			picW,picH=pic.size
			resPic=pic.resize((int(picW*scale),int(picH*scale)),Image.ANTIALIAS)
			resPic.save(outfile+'\\'+file,quality=100,dpi=(300,300))


#pic_resize(r'D:\[image]\_PicForTest_\wallpaper',0.1)
pic_resize(r'D:\[image]\_PicForTest_\wallpaper','128x1024')
